/**
 * 方法一：deteleObject 在数组对象中去掉重复的对象:https://www.cnblogs.com/gaoht/p/9850449.html
 * 方法二：ArrayReduce 根据数组对象中的key值进行去重
*/
var objArr = [
    {name: "1",age: "10",sex: "男",time: "2020"},
    {name: "1",age: "10",sex: "男",time: "2020"},
    {name: "1",age: "10",sex: "男",time: "2020"},
    {name: "1",age: "10",sex: "男",time: "2020"},
    {name: "2",age: "11",sex: "男",time: "2021"}
]
function deteleObject(obj) {
    var uniques = [];
    var stringify = {};
    for (var i = 0; i < obj.length; i++) {
        var keys = Object.keys(obj[i]);
        keys.sort(function (a, b) {
            return (Number(a) - Number(b));
        });
        var str = '';
        for (var j = 0; j < keys.length; j++) {
            str += JSON.stringify(keys[j]);
            str += JSON.stringify(obj[i][keys[j]]);
        }
        if (!stringify.hasOwnProperty(str)) {
            uniques.push(obj[i]);
            stringify[str] = true;
        }
    }
    uniques = uniques;
    return uniques;
}
/**
 * 打印：
 * [
 * { name: '1', age: '10', sex: '男', time: '2020' },
 * { name: '2', age: '11', sex: '男', time: '2021' }
 * ]
*/
console.log(deteleObject(objArr));

/**
 * 2、ArrayReduce 根据数组对象中的key值进行去重
*/
let arrObj = [
    {key: "1",name: "a"}, 
    {key: "1",name: "b"}, 
    {key: "2",name: "b"}
]
function ArrayReduce(array) {
    var obj = {};
    var redArray = array.reduce((cur, next) => {
        obj[next.key] ? "" : obj[next.key] = true && cur.push(next);
        return cur;
    }, []);
    return redArray;
}
/**
 * 打印：
 * [ { key: '1', name: 'a' }, { key: '2', name: 'b' } ]
*/
console.log(ArrayReduce(arrObj));